﻿using System.Collections.Generic;
using System.Drawing;
using System.Windows.Media;

namespace NewProcessGuarder.util
{
    public class ResourceHelper
    {
        private readonly Dictionary<string, object> pg_Resources = new Dictionary<string, object>();

        public Dictionary<string, object> Pg_Resources
        {
            get
            {
                return pg_Resources;
            }
        }

        private static ResourceHelper instance;

        private ResourceHelper() {
            Init();
        }

        public static ResourceHelper Instance {
            get
            {
                if (instance == null)
                {
                    instance = new ResourceHelper();
                }
                return instance;
            }
        }

        private void Init() {
            pg_Resources.Add("btnStart",
                getImg(Properties.Resources.btnStart));
            pg_Resources.Add("btnStop",
                getImg(Properties.Resources.btnStop));
            pg_Resources.Add("PerfCenterCpl",
                getImg(Properties.Resources.PerfCenterCpl));
        }
        

        private ImageSource getImg(object img) {
            ImageSource i = null;
            System.IO.MemoryStream memory = new System.IO.MemoryStream();
            if (img is Bitmap)
            {
                ((Bitmap)img).Save(memory, System.Drawing.Imaging.ImageFormat.Png);
            }
            else if (img is Icon)
            {
                ((Icon)img).Save(memory);

            }
            if (memory.Length > 0)
            {
                i = (ImageSource)((new ImageSourceConverter()).ConvertFrom(memory));
            }
            return i;
        }
    }
}
